import got from "got";
import { readFileByType } from "./util";

const prefixUrl = process.env.ICAN_PREFIXURL;
const postShareUrl = process.env.ICAN_POST_SHARE;
const token = readFileByType('access_token')
const org_id = readFileByType('org_id')

class ShareDTO {
  constructor(id: string) {
    this.relationId = id
  }
  "relationId": string
  "section" = "org"
  "markSource" = "wechat"
  "markTarget" = "wechat"
  "markType" = "share"
  "remark" = ""
}

const postShare = async () => {
  const headers = {
    authorization: `Bearer ${token}`
  }
  const postUrl = `${prefixUrl}${postShareUrl}`;
  const shareDto = new ShareDTO(org_id)
  try {
    const res = await got.post(postUrl, {
      method: "POST",
      headers,
      json: shareDto
    });
    return res;
  } catch (error) {
    console.error(error);
  }
}

export { postShare }